﻿@{ 
    string record = this.Request.Form["RecordNumber"];
    string location = this.Request.Form["location"];
    var query = MyModel.ghCrud.PageLoad(this.Request.UserHostAddress, this.Request.Form, ref record);


    Page.Title = "Laos Traveller";
    Layout = "LaosLayout.cshtml"; 
}
@section heady {
    <script type="text/javascript">
        function validateText() {


            if ($('textarea#TextBoxQueryImpure').val().length == 0) {
                alert("No text in HTML content text!");
                return false;
            }

            if ($('textarea#location').val().length == 0) {
                alert("No text in location!");
                return false;
            }
            MungeHTML();
            return true;
        }

        function submitFunction(buttonName) {

            // no validation for delete button or edit button
            if (buttonName == 'Add' || buttonName == 'Save')
            {
                if ($('textarea#TextBoxQueryImpure').val().length == 0) {
                    alert("No text in HTML content text!");
                    return false;
                }

                if ($('textarea#location').val().length == 0) {
                    alert("No text in location!");
                    return false;
                }
                MungeHTML();  
            }      
                  
            $('input#hit').val(buttonName);
            form1.submit();    
        }

        function MungeHTML() {

            var text = $('textarea#TextBoxQueryImpure').val();
            var clean = text.replace(/</g, '<=');
            clean = clean.replace(/&/g, '&=');
            $('input#pure').val(clean);
        }

        function getRecord() {
            submitFunction('Edit');
        }

    
    </script>
}
<h1>
    Laostraveller Guesthouses CRUD Editor</h1>
<br />
<div>
    @Html.Raw(MyModel.ghCrud.GetSingleRecordAsHTML(record))
</div>
<br />
<span id="Label2" style="display: inline-block; width: 70px;">HTML:</span>
<textarea name="TextBoxQueryImpure" rows="1" cols="1" id="TextBoxQueryImpure" style="height: 300px;
    width: 500px;">@query.Record</textarea>
<form name="form1" method="post" action="guesthousescrud.cshtml" id="form1" onsubmit="return validateText()">
<input type="hidden" id="pure" name="pure" />
<input type="hidden" id="hit" name="hit" />
<br />
<br />
<span id="Label1" style="display: inline-block; width: 70px;">Location:</span>
<textarea name="location" rows="1" cols="1" id="location" style="height: 20px; width: 200px;">@query.Location</textarea>
<br />
<br />

<span id="Label3" style="display: inline-block; width: 70px;">Select:</span>
@Html.DropDownList("RecordNumber", MyModel.ghCrud.GetAllOrderedByLocation(record), MyModel.ghCrud.GetAttributesLocations())
<br />
<br />
<input type="button" name="bAdd" value="Save (New)" id="bAdd" onclick="submitFunction('Add')"/>
<input type="button" name="bSave" value="Save (Replace)" id="bSave", onclick="submitFunction('Save')" />
<input type="button" name="bDel" value="Delete" id="bDel", onclick="submitFunction('Del')" />

</form>
<a href="guesthousesview.cshtml">view</a> 